#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        int n = nums.size();
        vector<vector<int>> dp(2, vector(n + 1, 1));

        for (int i = 1; i < n + 1; i++)
        {
            dp[0][i] = max(nums[i - 1], max(dp[0][i - 1] * nums[i - 1], dp[1][i - 1] * nums[i - 1]));
            dp[1][i] = min(nums[i - 1], min(dp[1][i - 1] * nums[i - 1], dp[0][i - 1] * nums[i - 1]));
        }
        int res = nums[0];
        for (int i = 0; i < 2; i++)
        {
            for (int j = 1; j < n + 1; j++)
            {
                res = max(dp[i][j], res);
            }
        }
        return res;

    }
};